package com.dy.basic.util;

import org.springframework.context.ApplicationContext;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

public class SendEmailUtil {

    public static void send(String text, String people){
        try {
            // 通过上下文获得对象
            ApplicationContext context = SpringUtil.getContext();
            JavaMailSender javaMailSender = context.getBean(JavaMailSender.class);
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");

            // 从这里开始抽取，填写发送有关内容
            helper.setFrom("1504842731@qq.com");
            helper.setSubject("审核结果通知");
            helper.setText(text);
            helper.setTo(people);
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}
